package com.sts.controller;

import java.util.ArrayList;
import java.util.List;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

import org.apache.log4j.Logger;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.alibaba.fastjson.JSON;
import com.sts.bean.Base_eq;
import com.sts.bean.Eq_run;
import com.sts.service.IBase_eqService;

/**
 * 基础数据controller
 */

@Controller
public class BaseController {
	
	@Resource
	private IBase_eqService bsS ;
	
	private Logger log = Logger.getLogger(this.getClass());
	
	@RequestMapping("/addBase_eq")
	@ResponseBody
	public String addBase_eq(String data){
		log.debug("addBase controller in");
		String result = "" ;
		log.debug("数据" + data);
		//将JSON对象转换为对象
		Base_eq base_eq = JSON.parseObject(data,Base_eq.class) ;
		log.debug(base_eq.toString());
		boolean b = bsS.addBase_eq(base_eq) ;
		if(b){
			result = "success" ;
		}else {
			result = "false" ;
		}
		
		
		log.debug("addBase controller out");
		return result;
	}
	
	
	
	/**
	 * 查询所有的设备信息并返回
	 */
	@RequestMapping(value="/showEq", produces="text/html;charset=UTF-8")
	@ResponseBody
	public String showEq(){
		log.debug("showEq controller in");
		String result = null ;
		List<Base_eq> list = new ArrayList<Base_eq>();
		list = bsS.selectBase();
		
		result = JSON.toJSONString(list);
		log.debug(result);
		log.debug("showEq controller out");
		
		return result;
		
	}
	
	@RequestMapping(value="/deleteById_C", produces="text/html;charset=UTF-8")
	@ResponseBody
	public String deleteById_C(){
		log.debug("deleteById_C controller in");
		
		String result = null;
		boolean b = bsS.deleteById_S() ;
		if(b){
			result = "success" ;
		}else {
			result = "false" ;
		}
		log.debug("deleteById_C controller out");
		return result;
		
	}
	
	@RequestMapping(value="/deleteAll_C", produces="text/html;charset=UTF-8")
	@ResponseBody
	public String deleteAll_C(){
		log.debug("deleteAll_C controller in");
		
		String result = null;
		boolean b = bsS.deleteAll_S() ;
		if(b){
			result = "success" ;
		}else {
			result = "false" ;
		}
		log.debug("deleteAll_C controller out");
		return result;
		
	}
	/**
	 * 对设备的运行数据信息进行查询
	 * @param stem
	 * @param stage
	 * @return
	 */
	@RequestMapping(value="/selectEqMsg",produces="text/html;charset=UTF-8")
	@ResponseBody
	public String selectEqMsg(String eq_id,String eq_name,String page,String limit){
		log.debug("selectEqMsg  controller out");
		log.debug("eq_id:" + eq_id + ",eq_name:" + ",page:" + page + ",limit:" +limit);
		List<Base_eq> list = null;
		list = bsS.selectEqMsg(eq_id,eq_name,page,limit);
		int length = bsS.selectEqNum(eq_id,eq_name);
		String str = JSON.toJSONString(list);
		str= "{\"code\":0,\"msg\":\"  \",\"count\":\""+length+"\",\"data\":"+str+"}";
		log.debug("哈哈哈的啊d+++:" + str);
		
		log.debug("selectEqMsg controller out");
		
		return str;
	}
	/**
	 * 对设备的运行数据信息进行查询
	 * @param stem
	 * @param stage
	 * @return
	 */
	@RequestMapping(value="/selectEqID",produces="text/html;charset=UTF-8")
	@ResponseBody
	public String selectEqID(){
		log.debug("selectEqID  controller out");
		List<Integer> list = new ArrayList<Integer>() ;
		list = bsS.selectEqID() ;
		String str = JSON.toJSONString(list);
		
		log.debug("哈哈哈的啊d+++:" + str);
		
		log.debug("selectEqID controller out");
		
		return str;
	}

}
